﻿using BattleBotsMattAndSunny.Model;
using Robocode;
using System;

namespace BattleBotsMattAndSunny.Extensions
{
    public static class EnemyExtensions
    {
        public static void UpdateEnemy(this Enemy enemy, ScannedRobotEvent e, AdvancedRobot robot)
        {
            if (enemy != null && e != null && robot != null)
            {
                enemy.X = robot.X + e.Distance * Math.Sin(e.BearingRadians);
                enemy.Y = robot.Y + e.Distance * Math.Cos(e.BearingRadians);
                enemy.Velocity = e.Velocity;
                enemy.HeadingChange = e.HeadingRadians - enemy.HeadingRadians;
                enemy.HeadingRadians = e.HeadingRadians;
                enemy.AbsoluteBearingRadians = robot.Heading + e.BearingRadians;
                enemy.Bearing = e.Bearing;
                enemy.PreviousEnergy = enemy.Energy;
                enemy.Energy = e.Energy;
            }
        }
    }
}